import { apiGet, apiPost, apiPut, apiDelete } from './client';
import { Memory, CreateMemoryPayload, UpdateMemoryPayload, MemoryQuery, MemoryStats } from './types';

export async function getMemories(query: MemoryQuery = {}) {
  const params = new URLSearchParams();
  if (query.type) params.append('type', query.type);
  if (query.tags) params.append('tags', query.tags.join(','));
  if (query.limit) params.append('limit', query.limit.toString());
  if (query.offset) params.append('offset', query.offset.toString());

  return apiGet<{ memories: Memory[]; total: number }>(`/memory?${params}`);
}

export async function getMemoryById(id: string) {
  return apiGet<Memory>(`/memory/${id}`);
}

export async function createMemory(payload: CreateMemoryPayload) {
  return apiPost<Memory>('/memory', payload);
}

export async function updateMemory(id: string, payload: UpdateMemoryPayload) {
  return apiPut<Memory>(`/memory/${id}`, payload);
}

export async function deleteMemory(id: string) {
  return apiDelete<void>(`/memory/${id}`);
}

export async function getMemoryStats() {
  return apiGet<MemoryStats>('/memory/stats');
}
